package org.getOffer;

/**
 * @Author yu
 * @Date 2021/6/4
 */
public class Practice04 {

    public static void main(String[] args) {

        int[][] ints={
                {1,   4,  7, 11, 15},
                {2,   5,  8, 12, 19},
                {3,   6,  9, 16, 22},
                {10, 13, 14, 17, 24},
                {18, 21, 23, 26, 30}
        };

        System.out.println(findNumberIn2DArray(ints, 3));

    }

    public static boolean findNumberIn2DArray(int[][] matrix, int target) {

        if (matrix==null||matrix.length==0||matrix[0].length==0){
            return false;
        }

        int rows=matrix.length,columns=matrix[0].length;
        int row=0,column=columns-1;
        while(row<rows&&column>=0){
            if (matrix[row][column]==target){
                return true;
            }else if (matrix[row][column]>target){
                column--;
            }else {
                row++;
            }
        }

        return false;

    }

}
